Skip to content

fix: check, snapshot and renders use the pinned Chrome, not an older one another tool cached - #5900

Merged
miguel-heygen merged 8 commits into
mainfrom
fix/cli-pinned-browser-first
Oct 19, 2026
Merged

miguel-heygen merged 8 commits into
mainfrom
fix/cli-pinned-browser-first

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

What

One rule now decides which chrome-headless-shell HyperFrames launches, in the CLI and in the engine:

  1. The pinned build: ours (~/.cache/hyperframes/chrome), then the shared Puppeteer cache (~/.cache/puppeteer/chrome-headless-shell). The pinned build is 152, or 150 on macOS 12.
  2. Otherwise, the newest shell in the shared cache that starts: it loads a blank page (--no-sandbox --dump-dom about:blank) and exits 0. It is probed once per path per process, with a 10 s limit, and the macOS 12 ceiling still applies. A skipped shell is logged under NODE_DEBUG=hyperframes:browser.

So an old shell that dies at launch is skipped, and a working stable shell (what npx @puppeteer/browsers install chrome-headless-shell puts there, as the CLI's own Linux hint suggests) is still used.

Why

A field report: on a Mac where another tool had once installed Puppeteer's chrome-headless-shell 121, hyperframes snapshot and check failed with net::ERR_ABORTED at http://127.0.0.1:<port>/. hyperframes doctor showed the cached mac_arm-121 shell dying with SIGTRAP on --version, and setting HYPERFRAMES_BROWSER_PATH to system Chrome fixed it.

The cause is the lookup order in findFromCache. It took the newest version directory in the shared Puppeteer cache, whatever its age, before looking at the pinned build in ~/.cache/hyperframes/chrome. "Usable" only meant a non-empty file, so a 121 that cannot start beat a working 152. render was not affected: it already asks for the pinned build (preferManagedChrome).

Related work

None open.

How

Every Chrome launch, and where it gets its binary:

Launch Binary comes from
render CLI ensureBrowser({ preferManagedChrome }) (preflight.ts), handed to the engine as PRODUCER_HEADLESS_SHELL_PATH (commands/render.ts), read first by resolveHeadlessShellPath
Studio server renders same env handoff (server/studioServer.ts)
check, snapshot, capture, layout, motion shots CLI ensureBrowser(), passed as executablePath to its own launch
benchmark, a standalone producer, the Lambda handler the engine resolves it itself (resolveHeadlessShellPath), which scanned the shared cache newest-first on its own

So the engine's resolver gets the same rule:

  • The rule lives once, in @hyperframes/engine/chrome-host-ceiling, which the CLI already imported:
    • managedChromeVersion, isManagedChromeDir and compareBrowserVersionsDescending move there.
    • shellStarts loads a blank page once per path. --dump-dom is headless Chrome's own print-and-exit mode on every platform, and it goes through the launch an old build dies in. --version was the first probe, but on Windows it may not exit, which would stall every non-pinned shell for the full limit.
    • pickSharedShell returns the shared cache's pinned build, else its newest starting shell.
  • Engine resolveHeadlessShellPath: the pinned build in our cache, then pickSharedShell on the shared cache. With neither, the newest build of ours, since the engine cannot download.
  • CLI findFromCache reads the pinned cache first, then the Puppeteer cache.
  • findFromPuppeteerCache uses pickSharedShell. The CLI's own copy of the version sort (parseVersionSegments, compareVersionDirsDescending) is gone in favour of the engine's.
  • An explicit choice still wins: HYPERFRAMES_BROWSER_PATH and PRODUCER_HEADLESS_SHELL_PATH come first, unchanged.
  • The embedded-captions scripts (preview-frames, check-overflow, check-rail-climax, measure-layout) launch what hyperframes browser path prints (hfBrowser in hf-cli.cjs), so they follow the same rule. Before, each hardcoded system Chrome. Without a CLI they still use system Chrome.

Behaviour changes

  • Someone who installed a non-pinned chrome-headless-shell with npx @puppeteer/browsers install and has no HyperFrames cache still gets it, if it starts. Only a shell that fails to start is skipped.
  • Engine-only renders (the SDK or the producer used directly, with no env override): before, any build in our cache came before the shared cache. Now it is our pinned build, then the newest shared shell that starts, then any build of ours. On a box whose HyperFrames cache holds only an older, non-pinned build, a newer shared shell now wins, and that can be a build someone else installed. The CLI, the shipped images and Lambda pass the env override, so they don't change.

Test plan

  • Unit tests updated in packages/cli/src/browser/manager.test.ts.
    • New: a Puppeteer cache holding only 121.0.6167.85 beside the pinned cache resolves to the pinned build.
    • New: a 121 that does not start is skipped.
    • New: with no pinned build, the newest working shell (148 over 99) is kept.
    • The first two fail on main, which returns the 121.
    • The test that pinned the old order ("prefers the puppeteer cache over the hyperframes cache when BOTH are populated") now asserts the pinned cache wins.
    • Puppeteer-cache fixtures name the pinned build.
  • Engine tests updated in packages/engine/src/services/browserManager.test.ts.
    • New: a shared cache holding only a linux-121.0.6167.85 that does not start resolves to nothing, where main returns the 121.
    • New, with real stub shells: one that dies with SIGTRAP is skipped, and the newest working one (148 over 99) is kept.
    • New: the pinned build in the shared cache beats an older build of ours (150), where main returns the 150.
    • The platform-matrix fixtures name the pinned build.
  • skills/embedded-captions/scripts/hf-cli.test.mjs: the scripts launch the path a stub CLI prints for browser path. It fails on main (hfBrowser is not a function).
  • The skills test passes three runs in a row on a Linux box.
  • Engine and CLI tsc --noEmit and the browser tests at this head: CI runs them.
  • On an arm64 Mac (macOS 26.5.1), outside any sandbox: Puppeteer's chrome-headless-shell 121.0.6167.85 dies with SIGTRAP on both --version and --dump-dom about:blank. The pinned 152.0.7977.30 prints its version and an empty page on both.
  • Not run on Windows. The probe is --dump-dom, which exits there too; that is inferred from Chrome's headless mode, not run.
  • Comments follow CONTRIBUTING.md.

@somanshreddy somanshreddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 3209128e. No blocker, so I'm approving. There's one behaviour change worth knowing about, below.

What I checked

  • Lookup order: findFromCache now reads our pinned cache, then a Puppeteer-cache dir only when its build equals managedChromeVersion(). That carries the macOS 12 pin (150) over without the ceiling helper. The env overrides (HYPERFRAMES_BROWSER_PATH, PRODUCER_HEADLESS_SHELL_PATH) still come first. A stale pinned path still flows through as ours, so staleHyperframesCachePath re-download behaviour is unchanged.
  • Tests: manager.test.ts passes 59 of 59, and tsc --noEmit is clean. The import that's left, chromeMajorCeiling, is still used at managedChromeVersion.
  • Mutation check: I restored the old order (Puppeteer cache first) and dropped the build match. 4 tests fail: the pinned-over-Puppeteer case, the lone-121 case, "never uses a puppeteer-cache shell at another build", and the macOS 12 "skips newer than 150".
  • Shipped images: packages/gcp-cloud-run/Dockerfile (148), packages/cli/src/docker/Dockerfile.render (@stable) and examples/k8s-jobs all install into the Puppeteer cache at a build other than 152. But they all export PRODUCER_HEADLESS_SHELL_PATH, or HYPERFRAMES_CHROME_PATH plus PRODUCER_…, so the env override wins and they don't change.

Behaviour change (intended, as far as I can tell; not a blocker)
A user who deliberately installed chrome-headless-shell with npx @puppeteer/browsers install at any build other than the pin, and has no HyperFrames cache, used to get that binary for check/snapshot. Now they get system Chrome, or a pinned download of about 100 MB on first run. That reverses the "respect an explicit prior choice" rule the old comment described. I found no doc that promised it, and HYPERFRAMES_BROWSER_PATH is still the escape hatch. A one-line debuglog saying "skipping puppeteer-cache

: not the pinned build" would make the switch visible in doctor output.

  • Dockerfile.test puts 148 in the Puppeteer cache and sets only PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium. So any CLI check/snapshot run inside that image now resolves differently, to system chromium or a download instead of the cached 148. CI on that image will show whether anything there depends on it.

CI was still running at the time of review, with 0 failing.

— Somu

@miguel-heygen miguel-heygen changed the title fix(cli): check and snapshot use the pinned Chrome, not an older one another tool cached fix: check, snapshot and renders use the pinned Chrome, not an older one another tool cached Oct 19, 2026
@miguel-heygen
miguel-heygen force-pushed the fix/cli-pinned-browser-first branch from b50e1cd to 45b1ab3 Compare October 19, 2026 18:50

@somanshreddy somanshreddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at a0bfd144. This is a rebase onto main plus a redesign: the engine now follows the same pinned-first rule, and shared shells are tried with --version. Requesting changes: the engine doesn't compile.

Blocker: missing imports in packages/engine/src/services/browserManager.ts
The import from ./chromeHostCeiling.js brings in only chromeMajorCeiling, exceedsChromeCeiling and isManagedChromeDir, but the file uses two more names:

  • pickSharedShell (line 220, in findSharedHeadlessShell).
  • compareBrowserVersionsDescending (lines 204 and 286, in findCachedHeadlessShell and resolveFullChromePath). The local copy was deleted, and the new export in chromeHostCeiling.ts isn't imported.

Evidence:

  • tsc --noEmit in packages/cli, which compiles engine sources, fails with:
    • browserManager.ts(220,51): TS7006 (implicit any)
    • browserManager.ts(286,42): TS2304: Cannot find name 'compareBrowserVersionsDescending'
  • packages/engine browserManager.test.ts has 10 failures, including every "selects only the host-compatible cached shell on …" case.
  • CI: Producer: unit tests is red, and Typecheck was still pending at the time of review.
  • At runtime, resolveHeadlessShellPath throws a ReferenceError for anyone without an env override, and so does resolveFullChromePath. The shipped images set PRODUCER_HEADLESS_SHELL_PATH, so they wouldn't hit it, but local and SDK renders would.

The fix should be just adding both names to the import.

On the design, once it compiles (not blocking)

  • shellStarts on Windows (inferred, not run). On Windows, Chrome's --version doesn't print-and-exit the way it does on Linux and macOS. If chrome-headless-shell.exe --version keeps running there, spawnSync blocks for the full 10 s per non-pinned dir, then reports "doesn't start". So on Windows every non-pinned shared shell would be skipped after a 10 s stall per process. The tests mock spawnSync. One real run on windows-latest would settle it.
  • Engine order changed. Before, any build in our cache came before the Puppeteer cache. Now it's our pinned build, then the shared cache's newest working shell, then any build in our cache. So an engine-only render (SDK or producer used directly, no env override) on a box whose ~/.cache/hyperframes holds an older, non-pinned build now picks a newer shared shell, which can be a Canary someone else installed. That's probably fine, but it's a render-determinism change for that setup, so it's worth a line in the PR.
  • What's still right: our pinned build comes first in both the CLI and the engine. A shared-cache dir at the pinned build is used without the --version probe. The ceiling skip is kept for macOS 12.

I'll re-review on the next pin.

— Somu

@somanshreddy somanshreddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 507bc655. I compared against a0bfd144: range-diff shows commits 1–5 as =, and three commits are new. The blocker is fixed. Approving, which replaces my changes-request.

The four points from my last review

  1. Missing imports (fixed). compareBrowserVersionsDescending and pickSharedShell are now imported in engine/src/services/browserManager.ts. Engine browserManager.test.ts passes 90 of 90, CLI manager.test.ts passes 60 of 60, and tsc --noEmit is clean. CI has 61 pass and 0 failing.
  2. The probe (answered). --no-sandbox --dump-dom about:blank loads a page and exits. I ran it on the three real shells on this Linux box: 144, 152.0.7977.42 and 152.0.7977.54 all exit 0. I didn't run it on Windows. The 10 s spawnSync timeout still caps any stall, and the result is cached per path.
  3. Engine order change. It's now written up under Behaviour changes in the PR description.
  4. Skipped shells are now logged. They show up under NODE_DEBUG=hyperframes:browser.

The caption-script change

  • hfBrowser() asks hyperframes browser path, first through hfCli(), then through a global hyperframes. If both fail, it falls back to system Chrome as before. Each attempt is in a try, and fs is in scope. hf-cli.test.mjs passes.
  • Skill/CLI version skew. Skills ship on merge. An older CLI without browser path would print help or an error; the last line isn't an existing file, so the script falls back to system Chrome. Nothing breaks.
  • Nit: browser path runs a full ensureBrowser() when nothing is found, so on a machine with no Chrome at all, the first caption-script call now downloads the pinned shell (about 100 MB). It's synchronous, with no timeout and stderr ignored, so it looks like a hang. A timeout on the execFileSync, or calling findBrowser only, would avoid that. This only affects a machine with no browser, which previously launched nothing useful anyway.
  • Caption measurement now uses headless shell instead of full Chrome. That matches what renders use, which is the point, but measure-layout results may shift slightly on machines that used to measure with system Chrome.

— Somu

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 163 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-center-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 50e7a59 Oct 19, 2026
116 of 117 checks passed
@miguel-heygen
miguel-heygen deleted the fix/cli-pinned-browser-first branch October 19, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants